package com.wangzhy.financial.controller;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.wangzhy.financial.domain.DeptYsKm;
import com.wangzhy.financial.service.IDeptYsKmService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 预算科目Controller
 *
 * @author wangzhy
 * @date 2021-11-15
 */
@RestController
@RequestMapping("/financial/ymkm")
@Api(tags = "预算科目")
public class DeptYsKmController extends BaseController
{
    @Autowired
    private IDeptYsKmService deptYsKmService;

    /**
     * 查询预算科目列表
     */
    @ApiOperation("查询预算科目列表")
    @PreAuthorize("@ss.hasPermi('financial:ymkm:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeptYsKm deptYsKm)
    {
        startPage();
        List<DeptYsKm> list = deptYsKmService.selectDeptYsKmList(deptYsKm);
        return getDataTable(list);
    }

    /**
     * 导出预算科目列表
     */
    @ApiOperation("导出预算科目列表")
    @PreAuthorize("@ss.hasPermi('financial:ymkm:export')")
    @Log(title = "预算科目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeptYsKm deptYsKm)
    {
        List<DeptYsKm> list = deptYsKmService.selectDeptYsKmList(deptYsKm);
        ExcelUtil<DeptYsKm> util = new ExcelUtil<DeptYsKm>(DeptYsKm.class);
        return util.exportExcel(list, "ymkm");
    }

    /**
     * 获取预算科目详细信息
     */
    @ApiOperation("获取预算科目详细信息")
    @PreAuthorize("@ss.hasPermi('financial:ymkm:query')")
    @GetMapping(value = "/{ysId}")
    public AjaxResult getInfo(@PathVariable("ysId") String ysId)
    {
        return AjaxResult.success(deptYsKmService.selectDeptYsKmById(ysId));
    }

    /**
     * 新增预算科目
     */
    @ApiOperation("新增预算科目")
    @PreAuthorize("@ss.hasPermi('financial:ymkm:add')")
    @Log(title = "预算科目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeptYsKm deptYsKm)
    {
        return toAjax(deptYsKmService.insertDeptYsKm(deptYsKm));
    }

    /**
     * 修改预算科目
     */
    @ApiOperation("修改预算科目")
    @PreAuthorize("@ss.hasPermi('financial:ymkm:edit')")
    @Log(title = "预算科目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeptYsKm deptYsKm)
    {
        return toAjax(deptYsKmService.updateDeptYsKm(deptYsKm));
    }

    /**
     * 删除预算科目
     */
    @ApiOperation("删除预算科目")
    @PreAuthorize("@ss.hasPermi('financial:ymkm:remove')")
    @Log(title = "预算科目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ysIds}")
    public AjaxResult remove(@PathVariable String[] ysIds)
    {
        return toAjax(deptYsKmService.deleteDeptYsKmByIds(ysIds));
    }
}
